package com.mvs.flyingbot;

import com.badlogic.gdx.Gdx;
import com.mvs.flyingbot.DynamicGameObject;
import com.mvs.flyingbot.World;

public class Robot extends DynamicGameObject {
	public static final int ROBOT_STATE_JUMP = 0;
	public static final int ROBOT_STATE_FALL = 1;
	public static final int ROBOT_STATE_HIT = 2;
	public static final float ROBOT_JUMP_VELOCITY = 11;
	public static final float ROBOT_MOVE_VELOCITY = 20;
	public static final float ROBOT_WIDTH = 1.2f;
	public static final float ROBOT_HEIGHT = 1.8f;
	public static final float JUMP_IMPULSE = 5;

	int state;
	float stateTime;

	public Robot(float x, float y) {
		super(x, y, ROBOT_WIDTH, ROBOT_HEIGHT);
		state = ROBOT_STATE_FALL;
		stateTime = 0;
	}

	public void update(float deltaTime) {
		velocity.add(0, World.gravity.y * deltaTime);
		position.mulAdd(velocity, Gdx.graphics.getDeltaTime());

		bounds.x = position.x - bounds.width / 2;
		bounds.y = position.y - bounds.height / 2;

		if (velocity.y > 0 && state != ROBOT_STATE_HIT) {
			if (state != ROBOT_STATE_JUMP) {
				state = ROBOT_STATE_JUMP;
				stateTime = 0;
			}
		}

		if (velocity.y < 0 && state != ROBOT_STATE_HIT) {
			if (state != ROBOT_STATE_FALL) {
				state = ROBOT_STATE_FALL;
				stateTime = 0;
			}
		}

		if (position.x < 0)
			position.x = 0;
		// position.x = World.WORLD_WIDTH;
		if (position.x > World.WORLD_WIDTH)
			// position.x = 0;
			position.x = World.WORLD_WIDTH;
		stateTime += deltaTime;
	}

	public void robotJump() {
		velocity.y = JUMP_IMPULSE;
		state = ROBOT_STATE_JUMP;
		stateTime = 0;

	}

}
